package com.sgb.kjwl.view.ui.adapter.machine;

import android.content.Context;
import android.graphics.drawable.Drawable;
import android.text.SpannableString;
import android.text.TextUtils;
import android.text.style.ImageSpan;
import android.view.View;

import com.sgb.kjwl.BR;
import com.sgb.kjwl.R;
import com.sgb.kjwl.databinding.ItemMachineListBinding;
import com.sgb.kjwl.model.entity.lease.LeaseListEntity;
import com.swgk.core.recyclerview.adapter.BaseRecycleAdapter;
import com.swgk.core.recyclerview.adapter.ItemViewHolder;

import java.util.List;

public class LeaseListAdapter extends BaseRecycleAdapter<LeaseListEntity> {

    public LeaseListAdapter(Context context, List<LeaseListEntity> datas) {
        super(context, R.layout.item_machine_list, datas);
    }

    @Override
    public void convert(ItemViewHolder holder, final LeaseListEntity entity) {
        holder.setBinding(BR.viewModel, entity);
        ItemMachineListBinding binding = (ItemMachineListBinding) holder.getmBinding();
        binding.tvArea.setText(entity.getCity() + entity.getArea());

        if ("1".equals(entity.getNegotiable())) {
            binding.priceView.setText("面议");
        } else {
            binding.priceView.setText(entity.getPrice() + " " + entity.getPriceUnit());
        }
        if (!TextUtils.isEmpty(entity.getDistance())) {
            binding.tvDistance.setVisibility(View.VISIBLE);
            binding.tvDistance.setText(entity.getDistance());
        } else {
            binding.tvDistance.setVisibility(View.GONE);
        }

        if ("1".equals(entity.getIsSelf())) {//是否自营，1为自营
            SpannableString spannableString = new SpannableString("  " + entity.getTitle());
            Drawable d = context.getResources().getDrawable(R.mipmap.ic_lease_isself);
            d.setBounds(0, 0, d.getIntrinsicWidth(), d.getIntrinsicHeight());
            spannableString.setSpan(new ImageSpan(d), 0, 1, ImageSpan.ALIGN_BASELINE);
            binding.titleView.setText(spannableString);
        } else {
            binding.titleView.setText(entity.getTitle());
        }

//        try {
//            binding.tvTime.setText(DateUtils.stampToDay(entity.getUpdatetime()));
//        } catch (Exception e) {
//
//        }
    }
}
